<template>
<div class="">
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    @close="close"
    :before-close="close"
    width="1100px">
      <el-form label-width="120px" :inline="true">
        <el-form-item label="所属地市：" >
          <el-input v-model="form.cityname"></el-input>
        </el-form-item>
        <el-form-item label="创建人：" >
          <el-input v-model="form.ctUserid"></el-input>
        </el-form-item>
        <el-form-item label="部门全称：" >
          <el-input v-model="form.deptdesc"></el-input>
        </el-form-item>
        <el-form-item label="部门编码：" >
          <el-input v-model="form.deptid"></el-input>
        </el-form-item>
        <el-form-item label="部门名称：" >
          <el-input v-model="form.deptname"></el-input>
        </el-form-item>
        <el-form-item label="部门成立日期：">
            <el-date-picker v-model="form.deptopendate" style="width:202px" value-format="yyyy-MM-dd H:mm:ss" type="date" placeholder="选择日期"> </el-date-picker>
        </el-form-item>
        <el-form-item label="部门定编：" >
          <el-input type="number" v-model="form.deptstaff"></el-input>
        </el-form-item>
        <el-form-item label="部门电话：" >
          <el-input v-model="form.depttel"></el-input>
        </el-form-item>
        <el-form-item label="组织状态：" >
            <el-radio v-model="form.disenable" :label="1">启用</el-radio>
            <el-radio v-model="form.disenable" :label="0">禁用</el-radio>
        </el-form-item>
        <el-form-item label="详细地址：" >
          <el-input v-model="form.dtladdress"></el-input>
        </el-form-item>
        <!-- <el-form-item label="组织层级：" >
          <el-input v-model="form.layer"></el-input>
        </el-form-item> -->
        <el-form-item label="排序优先值：" >
          <el-input v-model="form.orderindex"></el-input>
        </el-form-item>
        <el-form-item label="所属省份：" >
          <el-input v-model="form.provincename"></el-input>
        </el-form-item>
        <div style="text-align:right">
          <el-button type="primary" @click="add_dept" v-if="dialogType==='add'">立即添加</el-button>
          <el-button type="primary" @click="update_dept" v-if="dialogType==='update'">修改</el-button>
          <el-button @click="close">取 消</el-button>
        </div>
      </el-form>

  </el-dialog>
</div>
</template>

<script>
export default {
  props:["dialogType","dialogVisible","companyid","deptparentid","updateDeptInfo","addDept_submit"],
  data(){
    return {
      form:{
        companyid:this.companyid,
        disenable:1,
        deptparentid:this.deptparentid,
        orderindex:100,
        layer:0,
        deptopendate:''
      },
      title:'添加部门信息'
    }
  },
  methods:{
    add_dept(){
      this.addDept_submit(this.form);
    },
    update_dept(){
      this.$post("/dept/updateDept",this.form,data => {
        this.$message({
           message: '修改成功',
           type: 'success'
         });
         this.close();
        },error => {
          this.$message.error("错误");
      });
    },
    close(){
      this.$emit('update:dialogVisible', false)
    }
  },
  created(){
    if(this.dialogType === "update"){
      this.title = "修改部门信息";
      this.form.companyid = this.updateDeptInfo.companyid;
      this.form.disenable = this.updateDeptInfo.disenable;
      this.form.deptparentid = this.updateDeptInfo.deptparentid;
      this.form.orderindex = this.updateDeptInfo.orderindex;
      this.form.layer = this.updateDeptInfo.layer;
      this.form.provincename = this.updateDeptInfo.provincename;
      this.form.cityname = this.updateDeptInfo.cityname;
      this.form.ctUserid = this.updateDeptInfo.ctUserid;
      this.form.deptdesc = this.updateDeptInfo.deptdesc;
      this.form.deptid = this.updateDeptInfo.deptid;
      this.form.deptname = this.updateDeptInfo.deptname;
      this.form.deptopendate = this.updateDeptInfo.deptopendate;
      this.form.deptstaff = this.updateDeptInfo.deptstaff;
      this.form.depttel = this.updateDeptInfo.depttel;
      this.form.dtladdress = this.updateDeptInfo.dtladdress;
      this.form.id = this.updateDeptInfo.id;
    }
  }
}
</script>
